package ru.papergames.view.components.field
{
	import caurina.transitions.Tweener;
	import flash.display.Graphics;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import mx.core.UIComponent;
	
	

	public class PlaceSelector extends UIComponent
	{		
		
		public static const DBL_CLICK:String = 'PlaceSelector.DBL_CLICK';
		
		private var _color:uint = 0xDDDD22;
		
		public function PlaceSelector(color:uint = 0xDDDD22)
		{
			super();
			
			_color = color;
			
			tweenSelector();
		}
		
		private function onDblClick(evt:MouseEvent):void {						
			this.dispatchEvent(new Event(DBL_CLICK));
		}
		
		private function tweenSelector():void {
			Tweener.addTween(this, {alpha: 1 - this.alpha, time: 0.2, onComplete: tweenSelector});
		}
		
		override protected function commitProperties():void {
			super.commitProperties();			
			
		}
		
		override protected function updateDisplayList(w:Number, h:Number):void {
			super.updateDisplayList(w, h);			
			
			var g:Graphics = this.graphics;
			
			g.clear();			
			//g.lineStyle(1, 0, 0.8);
			g.beginFill(_color, 0.7);
			
			g.drawRect(1, 1, w-1, h-1);
			
			g.endFill();
		}
	}
}